package com.wise.service.cms.content.setting;

import com.wise.entities.content.Setting;
import com.wise.framework.daomodel.DaoSave;
import com.wise.framework.session.CurrentUserId;
import com.wise.framework.session.GetAcceptLanguage;
import com.wise.summer.v1.cms.content.setting.AddSetting;
import org.joda.time.DateTime;
import org.springframework.stereotype.Service;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;

import java.sql.Timestamp;

/**
 * @author futao
 * Created on 2019-06-19.
 */
@Service
@SummerService
public class AddSettingService implements SummerServiceBean<AddSetting> {
    @Override
    public void sum(AddSetting summer) {
        String lang = GetAcceptLanguage.s(true);
        String currentUserId = CurrentUserId.s(true);
        Timestamp currentTimestamp = new Timestamp(DateTime.now().getMillis());

        Setting setting = new Setting();
        setting.setName(summer.getName());
        setting.setInfo(summer.getInfo());
        setting.setLang(lang);
        setting.setCreationDate(currentTimestamp);
        setting.setCreatedBy(currentUserId);
        setting.setLastUpdateDate(currentTimestamp);
        setting.setLastUpdateBy(currentUserId);
        DaoSave.s(setting);
        summer.setSummerResult(setting);
    }
}
